using System;
using Karma.Framework.Core.Modules.Reports.Definition;
using Newtonsoft.Json;

namespace Karma.Framework.Core.Modules.Reports.Converter
{
    public class ReportSimpleConverter : JsonConverter
    {
        public override void WriteJson(JsonWriter writer, object value)
        {
            var report = value as Report;
            if (report == null)
            {
                throw new ArgumentException("Value debe ser un Entity", "value");
            }

            writer.WriteStartObject();
            writer.WritePropertyName("Id");
            writer.WriteValue(report.Id);
            writer.WritePropertyName("Name");
            writer.WriteValue(report.Name);

            writer.WriteEndObject();
        }

        public override object ReadJson(JsonReader reader, Type objectType)
        {
            throw new InvalidOperationException();
        }

        public override bool CanConvert(Type objectType)
        {
            return objectType.Equals(typeof(Report));
        }
    }
}